package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.entity.ItemBank;
import com.ruoyi.common.enums.IssueEnum;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.mapper.IssueMapper;
import com.ruoyi.system.service.IssueService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * 赵项阳
 *
 * @author DELL
 * @date 2022/6/6 16:17
 */
@Service
public class IssueServiceImpl implements IssueService {

    @Resource
    IssueMapper issueMapper;

    /**
     * 查询题库
     *
     * @param id 题库主键
     * @return 题库
     */
    @Override
    public ItemBank selectItemBankById(Long id)
    {
        return issueMapper.selectItemBankById(id);
    }

    /**
     * 查询题库列表
     *
     * @param itemBank 题库
     * @return 题库
     */
    @Override
    public List<ItemBank> selectItemBankList(ItemBank itemBank)
    {
        List<ItemBank> itemBanks = issueMapper.selectItemBankList(itemBank);
        itemBanks.forEach(s ->{
            String name = IssueEnum.getName(s.getVirtualExper());
            s.setVirtualExperName(name);
        });
        return itemBanks;
    }

    /**
     * 新增题库
     *
     * @param itemBank 题库
     * @return 结果
     */
    @Override
    public int insertItemBank(ItemBank itemBank)
    {
        itemBank.setCreateTime(DateUtils.getNowDate());
        return issueMapper.insertItemBank(itemBank);
    }

    /**
     * 修改题库
     *
     * @param itemBank 题库
     * @return 结果
     */
    @Override
    public int updateItemBank(ItemBank itemBank)
    {
        return issueMapper.updateItemBank(itemBank);
    }

    /**
     * 批量删除题库
     *
     * @param ids 需要删除的题库主键
     * @return 结果
     */
    @Override
    public int deleteItemBankByIds(Long[] ids)
    {
        return issueMapper.deleteItemBankByIds(ids);
    }

    /**
     * 删除题库信息
     *
     * @param id 题库主键
     * @return 结果
     */
    @Override
    public int deleteItemBankById(Long id)
    {
        return issueMapper.deleteItemBankById(id);
    }
}
